package com.xnsy.jishexiangmu.service.article.impl;

import com.xnsy.jishexiangmu.mapper.ArticleMapper;
import com.xnsy.jishexiangmu.pojo.Article;
import com.xnsy.jishexiangmu.service.article.ArticleService;
import com.xnsy.jishexiangmu.uitl.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Service
public class ArticleServiceImpl implements ArticleService {
    @Autowired
    private ArticleMapper articleMapper;

    @Override
    public List<Article> get() {
        Map<String, Object> map = ThreadLocalUtil.get();
        String username = (String) map.get("username");
        List<Article> article = articleMapper.get(username);
        return article;
    }

    @Override
    public void add(Article article) {
        Map<String, Object> map = ThreadLocalUtil.get();
        String username = (String) map.get("username");
        String toWhere = (String) map.get("toWhere");
        article.setUsername(username);
        article.setToWhere(toWhere);
        articleMapper.add(article);
    }

    @Override
    public void deleteArticle(int aid) {
        Map<String, Object> map = ThreadLocalUtil.get();
        String username = (String) map.get("username");
        articleMapper.deleteArticle(aid, username);
    }

    @Override
    public void fabuArticle(Integer aid) {
        Map<String, Object> map = ThreadLocalUtil.get();
        String username = (String) map.get("username");
        articleMapper.fabu(aid, username);
    }

    @Override
    public void updataArticle(Article article) {
        Map<String, Object> map = ThreadLocalUtil.get();
        String username = (String) map.get("username");
        article.setUsername(username);
        articleMapper.updataArticle(article);
    }

    @Override
    public List<Article> getAll() {
        return articleMapper.getAll();
    }

    @Override
    public Article getarticle(Integer id) {

        return articleMapper.getarticle(id);
    }
}
